import React, { useState } from 'react'
import './index.css'
type PropsType = {
    handleUpdataTodoList:(value:string) => void
}
export default function Header(props:PropsType){
    const [title, setTitle] = useState('')
    const handleEnter = (e:any)=> { 
        if(e.code === 'Enter'){
            if(title.trim() === '') {
                alert('NOT NULL')
                setTitle('')
                return 
            }
            props.handleUpdataTodoList(title)
            setTitle('')
        }
     }
  return (
  <div className='header'>
       <input type="text" autoFocus placeholder='请输入代办事件' 
       className='inp' value={title} onChange={(e) => setTitle(e.target.value)} 
       onKeyDown={(e)=>handleEnter(e)}/>
  </div>
  )
}